package me.leiusual.sharing.ui.mine.adapter

import android.view.View
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.view_holder_mine_address.*
import me.leiusual.sharing.api.model.Address

/**
 * author: leiusual
 * create on: 2019-07-29
 * description:
 */
class MineAddressViewHolder(
    override val containerView: View,
    private val clickListener: (Address) -> Unit,
    private val editListener: (Address) -> Unit
) : RecyclerView.ViewHolder(containerView), LayoutContainer, View.OnClickListener {

  lateinit var address: Address

  init {
    containerView.setOnClickListener(this)
    image_button_edit.setOnClickListener(this)
  }

  fun bind(address: Address) {
    this.address = address

    text_view_name.text = address.linkMan
    text_view_phone.text = address.contactPhone
    text_view_default.isVisible = address.defaulted
    text_view_address.text = address.provCityCounty + address.detailAddress
  }

  override fun onClick(v: View?) {
    when (v) {
      containerView -> clickListener(address)
      image_button_edit -> editListener(address)
    }
  }
}